package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.pojo.ChannelDo;
import org.example.response.StandardSubmit;
import org.example.service.ChannelService;
import org.example.service.CheckFilter;
import org.example.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.nio.channels.Channel;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RefreshScope

 @Slf4j
public class CheckController {
    @Autowired
    private Map<String, CheckFilter> checkFilterMap;

    @Value("${filters:}")
    private String filters;

    @Autowired
    private ChannelService channelService;


    @GetMapping("/checkFilter")
    public R checkFilter(HttpServletRequest request){

        List<String> strings = Arrays.asList(filters.split(","));


        strings.forEach(dto->{
            CheckFilter checkFilter = checkFilterMap.get(dto);
            checkFilter.check(null);
        });
        return R.ok();

    }




    @PostMapping(value="sendSingleMsg",produces = "application/json;charset=utf-8")
    public R sendSingleMsg(@RequestBody  @Validated StandardSubmit StandardSubmit){
        System.out.println(123);


     return R.ok();
    }


    @GetMapping(value="testData")


    public R testData(){
        System.out.println(123);
     List<ChannelDo>  list=   channelService.getAll();

        return R.ok();
    }


}
